package com.example.system.information;

import android.app.Application;
import android.content.Context;

import android.content.Intent;
import androidx.multidex.MultiDex;

import com.example.system.information.listener.CrashHandler;
import com.example.system.information.receiver.BluetoothBootBroadcastReceiver;
import com.example.system.information.utils.LogLocationUtils;
import com.example.system.information.utils.voice.SpeakUtils;
import com.lzy.okgo.OkGo;

import org.litepal.LitePal;

public class CrashApplication extends Application {

    private static final String TAG = CrashApplication.class.getSimpleName();

    private static Context mContext;

    private BluetoothBootBroadcastReceiver broadcastReceiver;

    @Override
    public void onCreate() {
        super.onCreate();

        mContext = this;

        // 删除冗余日志
        LogLocationUtils.deleteLog();

        LogLocationUtils.writeLog(TAG, "Gis应用启动");

        //初始化云知声语音
        SpeakUtils.getInstance().init(mContext);

        // 初始化LitePal数据库
        LitePal.initialize(mContext);

        // 开机自启动
        broadcastReceiver = new BluetoothBootBroadcastReceiver();

        //全局捕获异常并记录
        CrashHandler.getInstance().init();

        // 初始化OkGo
        OkGo.getInstance().init(this);

        if (MainActivity.mActivity == null) {
            LogLocationUtils.writeLog(TAG, "mainActivity未渲染");
            Intent mainActivity = new Intent(mContext, MainActivity.class);
            mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(mainActivity);
            LogLocationUtils.writeLog(TAG, "拉起mainActivity");
        }
    }

    public static Context getContext() {
        return mContext;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }
}
